
#include <BLabel>
#include <BGridLayout>
#include <BGroupBox>
#include <BVBoxLayout>

#include "PointRestraintPanel.h"

PointRestraintPanel::PointRestraintPanel(BWidget* parent) : BWidget(parent)
{
	BGroupBox* settingGroupBox = new BGroupBox("Setting");
	{
		BLabel* damplingLabel = new BLabel("Damping");
		_dampingSpinBox = new BRealSpinBox();

		BLabel* _impulseClampLabel = new BLabel("Impulse Clamp");
		_impulseClampSpinBox = new BRealSpinBox();

		BGridLayout* gridLayout = new BGridLayout(settingGroupBox);
		gridLayout->addWidget(1, 0, damplingLabel);
		gridLayout->addWidget(1, 1, _dampingSpinBox);
		gridLayout->addWidget(2, 0, _impulseClampLabel);
		gridLayout->addWidget(2, 1, _impulseClampSpinBox);
	}

	BVBoxLayout* vlayout = new BVBoxLayout(this);
	vlayout->addWidget(settingGroupBox);

	connect(this, Signal_AssetChanged, &PointRestraintPanel::slotAssetChanged);
	connect(_dampingSpinBox, Signal_EditFinished, &PointRestraintPanel::slotDamplingSpinBoxEditFinished);
	connect(_impulseClampSpinBox, Signal_EditFinished, &PointRestraintPanel::slotImpulseClampEditFinished);
}
PointRestraintPanel::~PointRestraintPanel()
{

}

void PointRestraintPanel::slotAssetChanged(BObject* object, const BValue& value)
{
	if (_pointRestraint = value)
	{
		_dampingSpinBox->setValue(_pointRestraint->damping());
		_impulseClampSpinBox->setValue(_pointRestraint->impulseLimit());
	}
}
void PointRestraintPanel::slotDamplingSpinBoxEditFinished(BObject* object, const BValue& value)
{
	BReal dampling = value;
	_pointRestraint->setDamping(dampling);
}
void PointRestraintPanel::slotImpulseClampEditFinished(BObject* object, const BValue& value)
{
	BReal impulseLimit = value;
	_pointRestraint->setImpulseLimit(impulseLimit);
}

